package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Description:
 *
 * @Author: yankaiyue
 * @Create: 2025/8/8 19:53
 * @Version: 1.0
 */
@RestController
public class OrderInfoController {
    @Autowired
    OrderInfoService orderInfoService;
    @RequestMapping("/getListNumber")
    public JSONObject getListNumber(){
        List<Map> list = orderInfoService.getListNumber();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        for (Map map : list) {
            jsonObject.put("data",map.get("money"));
        }
        return jsonObject;
    }
    @RequestMapping("/getListZhanBi")
    public JSONObject getListZhanBi() {
        List<Map> list = orderInfoService.getListZhanBi();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status", 0);
        jsonObject.put("msg", "");
        JSONArray data = new JSONArray();
        for (Map map : list) {
            JSONObject object = new JSONObject();
            object.put("name",map.get("name"));
            object.put("value",map.get("zhanbi"));
            data.add(object);
        }
        jsonObject.put("data",data);
        return jsonObject;
    }
    @RequestMapping("/getListLunBo")
    public JSONObject getListLunBo() {
        List<Map> list = orderInfoService.getListLunBo();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status", 0);
        jsonObject.put("msg", "");
        JSONObject data = new JSONObject();
        JSONArray columns = new JSONArray();
        JSONObject columns1 = new JSONObject();
        columns1.put("name","序号");
        columns1.put("id","start_org_id");
        columns.add(columns1);
        JSONObject columns2 = new JSONObject();
        columns2.put("name","机构");
        columns2.put("id","start_org_name");
        columns.add(columns2);
        JSONObject columns3 = new JSONObject();
        columns3.put("name","完成里程");
        columns3.put("id","total_distance");
        columns.add(columns3);
        JSONObject columns4 = new JSONObject();
        columns4.put("name","完成次数");
        columns4.put("id","num");
        columns.add(columns4);
        JSONObject columns5 = new JSONObject();
        columns5.put("name","完成时长");
        columns5.put("id","com_time");
        columns.add(columns5);
        JSONObject columns6 = new JSONObject();
        columns6.put("name","每次平均时长");
        columns6.put("id","avg_time");
        columns.add(columns6);
        JSONObject columns7= new JSONObject();
        columns7.put("name","每次平均里程");
        columns7.put("id","avg_distance");
        columns.add(columns7);
        data.put("columns",columns);
        JSONArray rows = new JSONArray();
        for (Map map : list) {
            JSONObject row = new JSONObject();
            row.put("start_org_id",map.get("start_org_id"));
            row.put("start_org_name",map.get("start_org_name"));
            row.put("total_distance",map.get("total_distance"));
            row.put("num",map.get("num"));
            row.put("com_time",map.get("com_time"));
            row.put("avg_time",map.get("avg_time"));
            row.put("avg_distance",map.get("avg_distance"));
            rows.add(row);
        }
        data.put("rows",rows);
        jsonObject.put("data",data);
        return jsonObject;
    }
    @RequestMapping("/getListProvince")
    public JSONObject getListProvince() {
        List<Map> list = orderInfoService.getListProvince();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status", 0);
        jsonObject.put("msg", "");
        JSONObject data = new JSONObject();
        JSONArray mapData = new JSONArray();
        for (Map map : list) {
            JSONObject object = new JSONObject();
            object.put("name",map.get("name"));
            object.put("value",map.get("province_num"));
            JSONArray tooltipValues = new JSONArray();
            tooltipValues.add(map.get("total_amount"));
            object.put("tooltipValues",tooltipValues);
            mapData.add(object);
        }
        data.put("mapData",mapData);
        data.put("valueName","省分运单数");
        JSONArray tooltipNames = new JSONArray();
        tooltipNames.add("运单总额");
        data.put("tooltipNames",tooltipNames);
        JSONArray tooltipUnits = new JSONArray();
        tooltipUnits.add("元");
        data.put("tooltipUnits",tooltipUnits);
        jsonObject.put("data",data);
        return jsonObject;
    }

    @RequestMapping("/getListZhiBiao")
    public  JSONObject getListZhiBiao(){
        Map list = orderInfoService.getListZhiBiao();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONArray data = new JSONArray();
        //1
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("name","接单数");
        jsonObject1.put("value",list.get("total_num"));
        data.add(jsonObject1);
        //2
        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("name","发单数");
        jsonObject2.put("value",list.get("send_order"));
        data.add(jsonObject2);
        //3
        JSONObject jsonObject3 = new JSONObject();
        jsonObject3.put("name","完成运单数数");
        jsonObject3.put("value",list.get("com_order"));
        data.add(jsonObject3);
        jsonObject.put("data",data);
        return jsonObject;
    }

    @RequestMapping("/getListZhu")
    public JSONObject getListZhu(){
        List<Map> list = orderInfoService.getListZhu();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject data = new JSONObject();
        JSONArray categories = new JSONArray();
        for (Map map : list) {
            categories.add(map.get("name"));
        }
        data.put("categories",categories);
        JSONArray series = new JSONArray();
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("name","名称");
        JSONArray data1 = new JSONArray();
        for (Map map : list) {
            data1.add(map.get("num"));
        }
        series.add(jsonObject1);
        jsonObject1.put("data",data1);
        data.put("series",series);
        jsonObject.put("data",data);
        return jsonObject;
    }
}
